module.exports = function($scope, $state, $stateParams,$resource,FileUploader,toaster, $http, $q){ 
  console.log($stateParams.scenicspot_id);
  $scope.info = {};
    $scope.info.nameid = '1';
    $scope.info.showflg = false;
  if($stateParams.scenicspot_id){
    
    
    $resource('/api/as/ggc/railmapdao/getScenicSpotByCode', {}, {}).save({'scenicspot_id':$stateParams.scenicspot_id},function (res) {
      if (res.errcode !== 0) {
        alert("数据获取失败");
        return;
      }
      res.data.nameid='2';
      $scope.info = res.data;
      $scope.info.showflg = true;
    });
  }

 // 上传图片
 var uploader1 = $scope.uploader1 = new FileUploader({
  url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
});

uploader1.filters.push({
  name: 'imageFilter',
  fn: function(item /*{File|FileLikeObject}*/, options) {
      var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
      return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
  }
});    
uploader1.onSuccessItem = function(fileItem, response, status, headers) {
  $scope.info.img = response.savename; 
};
// var fodata = new FormData();
// var fodata = {};
// //测试上传mp3 start

// var beforedata = {
//  //获取签名
//   'getosssing':
//   $http({
//     'method': 'POST',
//     'url': 'https://dlqt.juyouhx.com/Api/Api/getOssSing',
//   })
// };

// $scope.load = function(){
//   $q.all(beforedata).then(function (res) {
//     if (res.getosssing.data.status === 1) {
//       // fodata.append('signData',res.getosssing.data.result);
//       // fodata.append('key',res.getosssing.data.result.dir+'${filename}');
//       // fodata.append('policy',res.getosssing.data.result.policy);
//       // fodata.append('OSSAccessKeyId',res.getosssing.data.result.OSSAccessKeyId);
//       // fodata.append('signature',res.getosssing.data.result.signature);
//       // fodata.append('success_action_status','200');
//       fodata.signData = res.getosssing.data.result;
//       fodata.key = fodata.signData.dir+'${filename}';
//       fodata.policy = fodata.signData.policy;
//       fodata.OSSAccessKeyId = fodata.signData.accessid;
//       fodata.signature = fodata.signData.signature;
//       fodata.success_action_status = '200';
//     } else {
//       alert('获取签名失败');
//       return;
//     }
//   });
// }
// $scope.load();
// console.log(fodata);



var uploader2 = $scope.uploader2 = new FileUploader({
  // method: 'POST',
  url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb',
  // data: fodata,
  // headers: {  
  // 'Content-Type': undefined  
  // }
});

uploader2.filters.push({
  name: 'customFilter',
  fn: function(item /*{File|FileLikeObject}*/, options) {
    var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
    return '|mp3|'.indexOf(type) !== -1;
  }
});


uploader2.onSuccessItem = function(fileItem, response, status, headers) {
  if($scope.info.voice = null) {
    alert(response.msg);
  }
  console.log(fileItem);
  console.log(response);
  console.log(status);
  console.log(headers);
  $scope.info.voice = response.savename; 
};


//测试上传mp3 end
$scope.save =function() {
  $scope.info.scenicarea_id = $stateParams.code;
  $resource('/api/as/ggc/railmapdao/createScenicspotfromarea', {}, {}).save($scope.info,function (res) {
    // $scope.goback();
    if (res.errcode !== 0) {
      alert("创建失败");
      return;
    }else{
      toaster.success({ title: "提示", body: "创建成功!"});
      $state.go('app.scenicSpotList',{'code' : $stateParams.code});
    }
  });
};

$scope.update =function(scenicspot_id) {
  $scope.info.scenicspot_id = scenicspot_id;
  console.log(scenicspot_id);
  console.log($scope.info);
  $resource('/api/ac/ggc/railMapService/updateScenicSpotData', {}, {}).save($scope.info,function (res) {
    if (res.errcode !== 0) {
      alert("更新失败");
      return;
    }else{
      toaster.success({ title: "提示", body: "更改成功!"});
      $state.go('app.scenicSpotList',{'code' : $stateParams.code});
      // $scope.goback();
    }
  });
};

$scope.goback = function(code){
  $state.go('app.scenicSpotList',{'code' : $stateParams.code});
}
};